// pages/health/health.js
var app = getApp()


Page({


  /**
   * 页面的初始数据
   */
  data: {
    userId: '',
    bloodGlucose: '',
    measureType: '',
    measureTime: '',
    measurePhoto: '',
    abnormal: '',
    remark: '',
    diet_latest: []
  },

  toUser: function (e) {
    console.log('-------------click', e);
    wx.navigateTo({
      url: '../../pages/user/user?key="123"&name="ptt"',
    })
  },

  toSearchPage: function (e) {
    console.log('---click----toSearchPage------', e);
    wx.navigateTo({
      url: '../../pages/search/search?key="123"&name="ptt"',
    })
  },

  toSearchResultPage: function (e) {
    console.log('---click--toSearchResultPage--------', e);
    var search_key = e.currentTarget.dataset.text
    wx.navigateTo({
      url: '../../pages/search/result/result?search_key=' + search_key,
    })
  },

  click: function (e) {
    console.log('---click---------', e);
    wx.navigateTo({
      url: '/pages/record/add/addRecord',
    })
    console.log('-------------over');

  },


  myOnClick: function (event) {

  },

  toLoadBloodGlucoseLatest: function () {
    var searchUrl = app.globalData.bloodGlucoseLatestUrl
    console.log('searchUrl:' + searchUrl);
    var that = this;
    wx.request({
      url: searchUrl,
      data: {
        accss_token: app.accss_token,
        client_id: app.client_id,
        nonce: app.nonce,
        sign: app.sign,
        timestamp: app.timestamp
      },
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log('code:  ' + res.statusCode);
        if (res.statusCode == 200) {
          var result = res.data.result[0];
          // debugger
          that.setData({
            userId: result.userId,
            bloodGlucose: result.bloodGlucose,
            measureType: result.measureType,
            measureTime: result.measureTime,
            measurePhoto: result.measurePhoto,
            abnormal: result.abnormal,
            remark: result.remark,
          })
        } else {
        }
      },
      fail: function (err) {
        console.log(err)
      }
    }
    )
  },

  toLoadDietLatest: function () {
    var searchUrl = app.globalData.dietLatest
    console.log('searchUrl:' + searchUrl);
    var that = this;
    wx.request({
      url: searchUrl,
      data: {
        accss_token: app.accss_token,
        client_id: app.client_id,
        nonce: app.nonce,
        sign: app.sign,
        timestamp: app.timestamp
      },
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log('code:  ' + res.statusCode);
        if (res.statusCode == 200) {
          // debugger
          that.setData({
            diet_latest: res.data.result
          })
        } else {
        }
      },
      fail: function (err) {
        console.log(err)
      }
    }
    )
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.toLoadBloodGlucoseLatest()
    this.toLoadDietLatest()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
